/*
 ID: ning yusui
 LANG: JAVA
 TASK: butter
 */
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;

public class butter {
    Scanner in;
    PrintWriter out;

    public butter() throws IOException {
        in = new Scanner(new File(this.getClass().getName() + ".in"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(this.getClass().getName() +
                ".out")));
    }

    private final int SIZE = 801;
    int eq[] = new int[SIZE];
    int a[][] = new int[SIZE][SIZE];
    int dis[] = new int[SIZE];
    int farm[] = new int[SIZE];
    boolean v[] = new boolean[SIZE];
    int l[][] = new int[SIZE][SIZE];
    int n, p, c;
    int ans;

    void spfa(int s) {
        int h = 0, r = 1;
        eq[r] = s;
        v[s] = true;
        int now, st, u;
        do {
            h++;
            st = eq[(h - 1) % p + 1];
            for (int i = 1; i <= l[st][0]; i++) {
                u = l[st][i];
                if (dis[st] + a[st][u] < dis[u]) {
                    dis[u] = dis[st] + a[st][u];
                    if (!v[u]) {
                        r++;
                        eq[(r - 1) % p + 1] = u;
                        v[u] = true;
                    }
                }
            }
            v[st] = false;
        } while (h < r);
        now = 0;
        for (int i = 1; i <= n; i++)
            now += dis[farm[i]];
        if (ans > now)
            ans = now;
    }

    private void work() {
        ans = 0x7FFFFFFF;
        n = in.nextInt();
        p = in.nextInt();
        c = in.nextInt();
        for (int i = 1; i <= n; i++)
            farm[i] = in.nextInt();
        int x, y, z;
        for (int i = 1; i <= c; i++) {
            x = in.nextInt();
            y = in.nextInt();
            z = in.nextInt();
            l[x][0]++;
            l[x][l[x][0]] = y;
            a[x][y] = z;
            l[y][0]++;
            l[y][l[y][0]] = x;
            a[y][x] = z;
        }
        for (int i = 1; i <= p; i++) {
            Arrays.fill(dis, 1000 * 1000);
            Arrays.fill(v, false);
            dis[i] = 0;
            spfa(i);
        }
        out.println(ans);
        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        long start = System.currentTimeMillis();
        new butter().work();
        System.out.println(System.currentTimeMillis() - start + "ms");
    }
}
